home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / perl5 / Moose / Autobox.pm
Encoding:
Perl POD Document  |  2010-04-23  |  4.3 KB  |  186 lines

  1.  
  2. package Moose::Autobox;
  3. use 5.006;
  4. use strict;
  5. use warnings;
  6.  
  7. use Carp        qw(confess);
  8. use Scalar::Util ();
  9. use Moose::Util  ();
  10.  
  11. our $VERSION = '0.11';
  12.  
  13. use base 'autobox';
  14.  
  15. use Moose::Autobox::Undef;
  16.  
  17. sub import {
  18.     (shift)->SUPER::import(
  19.         DEFAULT => 'Moose::Autobox::',
  20.         UNDEF   => 'Moose::Autobox::Undef',
  21.     );
  22. }
  23.  
  24. sub mixin_additional_role {
  25.     my ($class, $type, $role) = @_;
  26.     ($type =~ /SCALAR|ARRAY|HASH|CODE/)
  27.         || confess "Can only add additional roles to SCALAR, ARRAY, HASH or CODE";
  28.     Moose::Util::apply_all_roles(('Moose::Autobox::' . $type)->meta, ($role));
  29. }
  30.  
  31. {
  32.                         
  33.     package Moose::Autobox::SCALAR;
  34.  
  35.     use Moose::Autobox::Scalar;
  36.  
  37.     use metaclass 'Moose::Meta::Class';
  38.  
  39.     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Scalar'));
  40.  
  41.     *does = \&Moose::Object::does;
  42.  
  43.     package Moose::Autobox::ARRAY;
  44.  
  45.     use Moose::Autobox::Array;
  46.  
  47.     use metaclass 'Moose::Meta::Class';
  48.  
  49.     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Array'));
  50.  
  51.     *does = \&Moose::Object::does;
  52.  
  53.     package Moose::Autobox::HASH;
  54.  
  55.     use Moose::Autobox::Hash;
  56.  
  57.     use metaclass 'Moose::Meta::Class';
  58.  
  59.     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Hash'));
  60.  
  61.     *does = \&Moose::Object::does;
  62.  
  63.     package Moose::Autobox::CODE;
  64.  
  65.     use Moose::Autobox::Code;
  66.  
  67.     use metaclass 'Moose::Meta::Class';
  68.  
  69.     Moose::Util::apply_all_roles(__PACKAGE__->meta, ('Moose::Autobox::Code'));
  70.  
  71.     *does = \&Moose::Object::does;            
  72.  
  73.                  
  74. 1;
  75.  
  76. __END__
  77.  
  78. =pod
  79.  
  80. =head1 NAME 
  81.  
  82. Moose::Autobox - Autoboxed wrappers for Native Perl datatypes 
  83.  
  84. =head1 SYNOPOSIS
  85.  
  86.   use Moose::Autobox;
  87.   
  88.   print 'Print squares from 1 to 10 : ';
  89.   print [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', ');
  90.  
  91. =head1 DESCRIPTION
  92.  
  93. Moose::Autobox provides an implementation of SCALAR, ARRAY, HASH
  94. & CODE for use with L<autobox>. It does this using a hierarchy of 
  95. roles in a manner similar to what Perl 6 I<might> do. This module, 
  96. like L<Class::MOP> and L<Moose>, was inspired by my work on the 
  97. Perl 6 Object Space, and the 'core types' implemented there.
  98.  
  99. =head2 A quick word about autobox
  100.  
  101. The L<autobox> module provides the ability for calling 'methods' 
  102. on normal Perl values like Scalars, Arrays, Hashes and Code 
  103. references. This gives the illusion that Perl's types are first-class 
  104. objects. However, this is only an illusion, albeit a very nice one.
  105. I created this module because L<autobox> itself does not actually 
  106. provide an implementation for the Perl types but instead only provides 
  107. the 'hooks' for others to add implementation too.
  108.  
  109. =head2 Is this for real? or just play?
  110.  
  111. Several people are using this module in serious applications and 
  112. it seems to be quite stable. The underlying technologies of L<autobox>
  113. and L<Moose::Role> are also considered stable. There is some performance
  114. hit, but as I am fond of saying, nothing in life is free. If you have 
  115. any questions regarding this module, either email me, or stop by #moose
  116. on irc.perl.org and ask around.
  117.  
  118. =head2 Adding additional methods
  119.  
  120. B<Moose::Autobox> asks L<autobox> to use the B<Moose::Autobox::*> namespace 
  121. prefix so as to avoid stepping on the toes of other L<autobox> modules. This 
  122. means that if you want to add methods to a particular perl type 
  123. (i.e. - monkeypatch), then you must do this:
  124.  
  125.   sub Moose::Autobox::SCALAR::bar { 42 }
  126.  
  127. instead of this:
  128.  
  129.   sub SCALAR::bar { 42 }
  130.  
  131. as you would with vanilla autobox.
  132.  
  133. =head1 METHODS
  134.  
  135. =over 4
  136.  
  137. =item B<mixin_additional_role ($type, $role)>
  138.  
  139. This will mixin an additonal C<$role> into a certain C<$type>. The 
  140. types can be SCALAR, ARRAY, HASH or CODE.
  141.  
  142. This can be used to add additional methods to the types, see the 
  143. F<examples/units/> directory for some examples.
  144.  
  145. =back
  146.  
  147. =head1 TODO
  148.  
  149. =over 4
  150.  
  151. =item More docs
  152.  
  153. =item More tests
  154.  
  155. =back
  156.   
  157. =head1 BUGS
  158.  
  159. All complex software has bugs lurking in it, and this module is no 
  160. exception. If you find a bug please either email me, or add the bug
  161. to cpan-RT.
  162.  
  163. =head1 AUTHOR
  164.  
  165. Stevan Little E<lt>stevan@iinteractive.comE<gt>
  166.  
  167. B<with contributions from:>
  168.  
  169. Anders (Debolaz) Nor Berle
  170.  
  171. Matt (mst) Trout
  172.  
  173. renormalist
  174.  
  175. =head1 COPYRIGHT AND LICENSE
  176.  
  177. Copyright 2006-2008 by Infinity Interactive, Inc.
  178.  
  179. L<http://www.iinteractive.com>
  180.  
  181. This library is free software; you can redistribute it and/or modify
  182. it under the same terms as Perl itself.
  183.  
  184. =cut
  185.